package admin_image_api

import (
	"blog_go/global"
	"blog_go/models"
	"blog_go/models/res"
	"fmt"
	"github.com/gin-gonic/gin"
)

// ImagesDel 图片删除
// @Tags 图片管理
// @Summary 图片删除
// @Description 图片删除
// @Param params body models.DeleteRequest true "入参json"
// @Param token header string true "token"
// @Router /api/admin/image/del [delete]
// @Produce json
// @Success 200 {object} res.Response{data=bool}
func (AdminImageAPI) ImagesDel(c *gin.Context) {
	var delReq models.DeleteRequest
	err := c.ShouldBindJSON(&delReq)
	//err = errors.New("aaa")
	if err != nil {
		panic(res.ParamError)
	}
	var bannerList []models.ImageModel
	// 第二个参数id的集合,默认就是根据id去查询
	global.DB.Find(&bannerList, delReq.IdList)
	affected := global.DB.Delete(&bannerList).RowsAffected
	if affected > 0 {
		res.OkWithMessage(fmt.Sprintf("删除图片%d长", affected), c)
		return
	}
	res.FailWithMessage("不存在该文件", c)
}
